import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Register from '@/views/login/register.vue'
import BasicInfo from '@/views/profile/BasicInfo.vue'
import EditBasicInfo from '@/views/profile/EditBasicInfo.vue'
import SurgeryInfo from '@/views/profile/SurgeryInfo.vue'
import HistoryInfo from '@/views/profile/HistoryInfo.vue'
import AllergyInfo from '@/views/profile/AllergyInfo.vue'
import PersonalHistory from '@/views/profile/PersonalHistory.vue'

// 主要tabbar
export const layoutRoutes: Array<RouteRecordRaw> = [
	{ path: '/', name: 'home', meta: { title: 'home', keepAlive: true }, component: () => import('@/views/home/index.vue') },
	{
		path: '/category',
		name: 'category',
		meta: {
			title: 'category',
			// keepAlive: true,
		},
		component: () => import('@/views/category/index.vue'),
	},
	{ path: '/mycenter', name: 'mycenter', meta: { title: 'mycenter' }, component: () => import('@/views/mycenter/index.vue') },
	{ path: '/medical-record', name: 'medical-record', meta: { title: '病历档案' }, component: () => import('@/views/medical/MedicalRecord.vue') },
	{ path: '/shopcart', name: 'shopcart', meta: { title: 'shopcart' }, component: () => import('@/views/shopcart/index.vue') },
	{ path: '/assessment', name: 'assessment', meta: { title: 'assessment' }, component: () => import('@/views/assessment/index.vue') },
	{ path: '/assessment/questionnaire', name: 'assessment-questionnaire', meta: { title: 'assessment-questionnaire' }, component: () => import('@/views/assessment/questionnaire.vue') },
	{ path: '/assessment/questionnaire/fill', name: 'questionnaire-fill', meta: { title: '问卷填写', hideTabBar: true }, component: () => import('@/views/assessment/QuestionnaireFill.vue') },
	// 测试页面的组件
	{ path: '/one', name: 'one', meta: { title: 'one' }, component: () => import('@/views/testPage/one.vue') },
]

export const routes: Array<RouteRecordRaw> = [
	{
		path: '/',
		component: () => import('@/layout/index.vue'),
		redirect: '/index',
		// 需要layout的页面
		children: layoutRoutes,
	},

	{ path: '/login', name: 'login', component: () => import('@/views/login/index.vue') },
	{ path: '/account', name: 'account', component: () => import('@/views/account.vue') },
	{
		path: '/register', 
		name: 'Register',
		component: Register
	},
	{
		path: '/basic-info',
		name: 'BasicInfo',
		component: BasicInfo
	},
	{
		path: '/edit-basic-info',
		name: 'EditBasicInfo',
		component: EditBasicInfo
	},
	{
		path: '/surgery-info',
		name: 'SurgeryInfo',
		component: SurgeryInfo
	},
	{
		path: '/history-info',
		name: 'HistoryInfo',
		component: HistoryInfo
	},
	{
		path: '/allergy-info',
		name: 'AllergyInfo',
		component: AllergyInfo
	},
	{
		path: '/personal-history',
		name: 'PersonalHistory',
		component: PersonalHistory
	},

	// 替代vue2中的'*'通配符路径
	{ path: '/:pathMatch(.*)*', redirect: '/' },
]

const router = createRouter({ scrollBehavior: () => ({ left: 0, top: 0 }), history: createWebHashHistory(), routes })

router.beforeEach((_to, _from, next) => {
	next()
})

export default router
